package pong.ui.sound;

import java.io.File;

import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;

public class SoundPlayer {

private Sequencer sequencer;
	
	private static final String BALL_IMPACT_FILEPATH = "";

	private static SoundPlayer instance;
	
	private SoundPlayer(){
		// Private constructor for singleton pattern.
	}
	
	public static SoundPlayer getInstance() {
		if(instance == null) {
			instance = new SoundPlayer();
		}
		return instance;
	}
	
	public void playBallImpactOnBat(){
		playSound(BALL_IMPACT_FILEPATH);
	}
	
	private void playSound(String filename){
		try {
			  Sequence sequence = MidiSystem.getSequence(new File(filename));
			  this.sequencer = MidiSystem.getSequencer();
			  this.sequencer.open();
			  this.sequencer.setSequence(sequence);
			  this.sequencer.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
